﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace ChoJu.Converters
{
    public class EmptyVisbilityConverter : IValueConverter
    {
        public bool IsReversal { get; set; } = false;

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value is int)
            {
                var val = (int)value;
                if (val == 0)
                    return IsReversal == false ? Visibility.Collapsed : Visibility.Visible;
                else
                    return IsReversal == false ? Visibility.Visible : Visibility.Collapsed;
            }

            else if(value is bool)
            {
                var val = (bool)value;
                if (val == false)
                    return IsReversal == false ? Visibility.Collapsed : Visibility.Visible;
                else
                    return IsReversal == false ? Visibility.Visible : Visibility.Collapsed;
            }

            if (string.IsNullOrEmpty(value?.ToString()) == true)
                return IsReversal == false ? Visibility.Collapsed : Visibility.Visible;
            else
                return IsReversal == false ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
